home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / fftplot < prev    next >
Text File  |  1994-09-23  |  1KB  |  49 lines

  1. //---------------------------------------------------------------------------
  2. //  fftplot.r
  3.  
  4. //  Syntax:    fftplot ( Y )
  5. //        fftplot ( Y , T )
  6.  
  7. //  Fftplot compute and plot the magnitude in dB and phase in degrees
  8. //  of the FFT data in Y
  9. //
  10. //  T = sampling period, if this parameter is not given it is assumed
  11. //      to be equal to one.
  12.  
  13. //  The magnitude and phase are returned in list elements `mag' and
  14. //  `ph' respectively. The values for the frequency scale are returned
  15. //  in list element `freq'. The magnitude and phase are truncated
  16. //  above the Nyquist frequency. If plotf exists, then a plot of the
  17. //  magnitude of Y (in dB) versus frequency is produced.
  18. //
  19. //---------------------------------------------------------------------------
  20.  
  21. fftplot = function ( Y, T, plotf )
  22. {
  23.  
  24.   lab = ["DIGITAL FREQUENCY / pi" , "FREQUENCY HERTZ"];
  25.   ly = log (Y[:]);
  26.   mag = 20 * real(ly) / log(10);
  27.   ph = imag (ly);
  28.   n = max (size (Y))/2;
  29.   f = ((0:n-1)/n)';
  30.   if (!exist (T)) 
  31.   { 
  32.     labid = 1;
  33.   else
  34.     f = 0.5*f/T;
  35.     labid = 2;
  36.   }
  37.  
  38.   if (exist (plotf))
  39.   {
  40.     plot ("set title 'MAGNITUDE'");
  41.     plot ("set xlabel '"+lab[labid]+"'");
  42.     plot ("set ylabel 'dB'");
  43.  
  44.     plot ( [f, mag[1:n] ] );
  45.   }
  46.  
  47.   return << freq = f; mag = mag[1:n]; ph = ph[1:n] >>
  48. };
  49.